package com.scalar.chiptrack.adaptor.akrossilicon.unisem;

import com.scalar.chiptrack.jobs.JobHandler;
import com.scalar.chiptrack.adaptor.AdaptorConstants;
import com.scalar.chiptrack.adaptor.AssemblyLot;
import com.scalar.chiptrack.adaptor.InventoryLot;
import com.scalar.chiptrack.adaptor.AdaptorUtils;
import com.scalar.chiptrack.adaptor.TestLot;
import com.scalar.chiptrack.adaptor.utils.ParserResult;
import com.scalar.chiptrack.adaptor.utils.Parser;
import com.scalar.chiptrack.adaptor.utils.ParserFactory;
import com.scalar.chiptrack.adaptor.utils.JXLXLSParserImpl;
import com.scalar.chiptrack.adaptor.dao.InventoryLotDAO;
import com.scalar.chiptrack.adaptor.dao.AssemblyAdaptorDAO;
import com.scalar.chiptrack.adaptor.dao.ShippedLotDAO;
import com.scalar.chiptrack.adaptor.dao.AdaptorDAO;
import com.scalar.chiptrack.adaptor.dao.AdaptorRunInfo;
import com.scalar.chiptrack.adaptor.dao.TestAdaptorDAO;
import com.scalar.chiptrack.adaptor.dao.NewAdaptorDAO;
import com.scalar.chiptrack.utils.Logger;
import com.scalar.chiptrack.utils.StringUtils;
import com.scalar.chiptrack.operations.process.dao.NewProductDAO;
import com.scalar.chiptrack.operations.process.ParameterTypes;
import com.scalar.ScalarException;

import java.util.HashMap;
import java.util.ArrayList;
import java.util.Date;
import java.io.File;

/**
 * Created by IntelliJ IDEA.
 * User: munugoti
 * Date: 17 Feb, 2010
 * Time: 3:31:14 PM
 */
public class UNISEMDataParser extends JobHandler implements AdaptorConstants
{
    private static Logger m_parserLogger     = null;
    private String m_dataOutputDir           = null;

    private HashMap<String, AssemblyLot> m_assyWipDataMap = new HashMap<String, AssemblyLot>();
    private HashMap<String, InventoryLot> m_dieBankDataMap= new HashMap<String, InventoryLot>();
    private HashMap<String, TestLot> m_testDataMap          = new HashMap<String, TestLot>();
    private HashMap<String, InventoryLot> m_trDataMap	    = new HashMap<String, InventoryLot>();
    private HashMap<String, InventoryLot> m_fgDataMap	    = new HashMap<String, InventoryLot>();

    public UNISEMDataParser() throws ScalarException
    {
       try
       {
           m_dataOutputDir = AdaptorUtils.getDataOutputDir(VENDOR_NAME_UNISEM, WIP_TYPE_ASSEMBLY);
           AdaptorUtils.makeAllAdaptorDirs(m_dataOutputDir);
           m_parserLogger = AdaptorUtils.getDataParserLogger(m_dataOutputDir, VENDOR_NAME_UNISEM);
           InventoryLotDAO.setLogger(m_parserLogger);
           AssemblyAdaptorDAO.setLogger( m_parserLogger );
           TestAdaptorDAO.setLogger( m_parserLogger );
           ShippedLotDAO.setLogger(m_parserLogger);
           AdaptorUtils.setLogger( m_parserLogger);
       }
       catch ( ScalarException se )
       {
           log( "ERROR!! ERROR!! ERROR!! Exception while loading UNISEM WIP Status output directory details from database, Exception: " + se );
           throw se;
       }
    }

    public static void main( String args[] ) throws Exception
    {
       new UNISEMDataParser().execute();
    }


    public void execute() throws Exception
    {

       AdaptorUtils.printHeader(VENDOR_NAME_UNISEM, CONSTANT_PARSER);

       File doneDestDir = new File( m_dataOutputDir + "/done");

       File wipDataoutDir = new File( m_dataOutputDir );

       File[] fileList = wipDataoutDir.listFiles();

       if ( ( fileList == null ) || ( fileList.length <= 3 ) )
       {
           log( "No file found in directory: " + wipDataoutDir );
           throw new ScalarException( "No file found in directory: " + wipDataoutDir + "----\n\n" );
       }

       ArrayList<File> successFileList    = new ArrayList<File>();
       boolean success              = false;

       //PARSING STARTS FROM HERE
       for ( int i = 0; i < fileList.length; i++ )
       {

           if ( fileList[i].isDirectory() )
           {
               continue;
           }
           //System.out.println("fileList[i].getName() = " + fileList[i].getName());
           if ( ( fileList[i].getName() != null ) && ( fileList[i].getName().trim().startsWith ( UNISEMPOP3Adaptor.FILE_NAME_ASSY_WIP ) ) )
           {
               try
               {
                    parseWipReport( fileList[i].getAbsolutePath() );

                    //Add files to success list to move to /done directory
                    successFileList.add( fileList[i] );
                    success = true;
               }
               catch ( Exception e )
               {
                   success = false;
                   log( "Exception while parsing and storing file: " + fileList[i].getName() + "\nException: " + e );
                   e.printStackTrace();
                   throw e;
               }
           }
           if ( ( fileList[i].getName() != null ) && ( fileList[i].getName().trim().startsWith ( UNISEMPOP3Adaptor.FILE_NAME_FT_WIP ) ) )
           {
               try
               {
                    parseTestWipReport( fileList[i].getAbsolutePath() );

                    //Add files to success list to move to /done directory
                    successFileList.add( fileList[i] );
                    success = true;
               }
               catch ( Exception e )
               {
                   success = false;
                   log( "Exception while parsing and storing file: " + fileList[i].getName() + "\nException: " + e );
                   e.printStackTrace();
                   throw e;
               }
           }
      }
      // to save the Die Bank lot tables
       try
       {
           if ( m_dieBankDataMap.isEmpty() == false )
           {
               log(" Updating Die Bank Lot Information");
               InventoryLotDAO.saveInventoryLot( null, m_dieBankDataMap.values().iterator(), INVENTORY_TYPE_DIE_BANK, VENDOR_NAME_UNISEM );
               success = true;
           }
           else
           {
               InventoryLotDAO.closeInventoryLot(null, INVENTORY_TYPE_DIE_BANK, VENDOR_NAME_UNISEM  );
           }
      }
      catch (ScalarException se)
      {
          success = false;
          se.printStackTrace();
          log("ERROR!! ERROR!! ERROR!! Could not update Die Bank Lot information into database: " + se);
          throw se;
      }

       // to save the Assembly lot tables
       try
       {
           if ( m_assyWipDataMap.isEmpty() == false )
           {
               log(" Updating Assembly Lot Information");
               AssemblyAdaptorDAO.saveAssemblyLot( null, m_assyWipDataMap.values().iterator(), WIP_TYPE_ASSEMBLY, VENDOR_NAME_UNISEM );
               success = true;
           }
           else
           {
               AssemblyAdaptorDAO.closeAssemblyLot(null, WIP_TYPE_ASSEMBLY, VENDOR_NAME_UNISEM );
           }
      }
      catch (ScalarException se)
      {
          success = false;
          se.printStackTrace();
          log("ERROR!! ERROR!! ERROR!! Could not update Assembly Lot information into database: " + se);
          throw se;
      }

        try
        {
           // Saving FINAL TEST Information
           if ( m_testDataMap.isEmpty() == false )
            {
                log( " Updating Test Lot Information" );
                TestAdaptorDAO.saveTestLot( null,m_testDataMap.values().iterator(), LOCATION_TYPE_FT, VENDOR_NAME_UNISEM );
            }
            else
           {
               TestAdaptorDAO.closeTestLot( null, LOCATION_TYPE_FT, VENDOR_NAME_UNISEM );
           }

           success = true;
        }
        catch ( ScalarException se )
        {
            success = false;
            se.printStackTrace();
            log( "ERROR!! ERROR!! ERROR!! Could not update Test Lot information into database: " + se );
            throw se;
        }

        // to save the Tape & Reel lot info
       try
       {
          if ( m_trDataMap.isEmpty() == false )
          {
              log(" Updating Tape & Reel Lot Information");
              InventoryLotDAO.saveInventoryLot( null, m_trDataMap.values().iterator(), LOCATION_TYPE_TAPE_REEL, VENDOR_NAME_UNISEM );
              success = true;
          }
          else
          {
              InventoryLotDAO.closeInventoryLot(null, LOCATION_TYPE_TAPE_REEL, VENDOR_NAME_UNISEM );
          }
     }
     catch (ScalarException se)
     {
         success = false;
         se.printStackTrace();
         log("ERROR!! ERROR!! ERROR!! Could not update Tape & reel Lot information into database: " + se);
         throw se;
     }

       // to save the Finished Goods lot tables
      try
      {
          if ( m_fgDataMap.isEmpty() == false )
          {
              log(" Updating Finished Goods Lot Information");
              InventoryLotDAO.saveInventoryLot( null, m_fgDataMap.values().iterator(), LOCATION_TYPE_FG, VENDOR_NAME_UNISEM );
              success = true;
          }
          else
          {
              InventoryLotDAO.closeInventoryLot(null, LOCATION_TYPE_FG, VENDOR_NAME_UNISEM );
          }
     }
     catch (ScalarException se)
     {
         success = false;
         se.printStackTrace();
         log("ERROR!! ERROR!! ERROR!! Could not update Finished Goods Lot information into database: " + se);
         throw se;
     }


       // To Close the Drop Out Lots
       AdaptorDAO.closeDropOutLots( VENDOR_NAME_UNISEM );

       // TO SEND THE NEW LOTS, NEW TRANSIT LOTS, NO PO LOTS, DISCREPANCY LOTS NOTIFICATIONS TO THE USER
       AdaptorDAO.sendAllNotifications( VENDOR_NAME_UNISEM, true, true, true );


       int adaptor_id = AdaptorRunInfo.getLastRunAdaptorId( UNISEMPOP3Adaptor.ADAPTOR_NAME, CONSTANT_ADAPTOR);

        // Update Adaptor_Run_Info table
        try
        {
            if ( success == true )
            {
                AdaptorRunInfo.saveAdaptorLastUpdatedStatus(CONSTANT_PARSER, UNISEMPOP3Adaptor.ADAPTOR_NAME, CONSTANT_SUCCESS, adaptor_id);
                System.out.println( "SUCCESSFULLY UPDATED IN THE DATABASE" );
            }
        }
        catch ( ScalarException se )
        {
            success = false; //As filES DATA SAVED , UPDATEING AS SUCCESS
            AdaptorRunInfo.saveAdaptorLastUpdatedStatus(CONSTANT_PARSER, UNISEMPOP3Adaptor.ADAPTOR_NAME, CONSTANT_SUCCESS, adaptor_id);
            log( "WARNING!! WARNING!! WARNING!! Could not update Adaptor run information, Exception: " + se );
            throw se;
        }

       // Step 7
       // Move the successful files to 'done' directory
       if ( success )
       {
           AdaptorUtils.moveFilesToDone(successFileList, doneDestDir );
       }
   }//end of execute method


   public void parseWipReport( String fileName ) throws Exception
   {
        if ( fileName == null ) throw new ScalarException( "Filename argument is null" );

        ParserResult result            = null;

        InventoryLot inventoryLot   = null;
        AssemblyLot assemblyLot     = null;
        String partNumber           = null;
        String lotNumber            = null;
        String fabLotNumber         = null;

        try
        {
            File detailWipFile = new File( fileName );
            if ( !detailWipFile.exists() )
            {
                throw new ScalarException( fileName + " doesnt exist" );
            }

            Parser parser = ParserFactory.getJXLXLSParser( detailWipFile );
            log( "\nFound " + fileName );
            log( "\nParsing the file for Wip Report..." );
            System.out.println( "\nFound " + fileName );
            System.out.println( "\nParsing the file for Wip Report..." );

            ((JXLXLSParserImpl)parser).setHeaderRowIdx(5);
            ((JXLXLSParserImpl)parser).setDataStartRowIdx(6);

            result = parser.parse();

            while ( result.next() )
            {
                fabLotNumber = result.getString("Lot Num");
                partNumber = result.getString("Device");
                lotNumber  = result.getString("Lot Num");

                if ( lotNumber != null && lotNumber.trim().length() > 0 && partNumber != null && partNumber.trim().length() > 0)
                {
                    if ( lotNumber.indexOf("@") != -1 )
                    {
                        lotNumber = lotNumber.split("@")[0];
                        fabLotNumber = lotNumber;
                    }

                    //DIE BANK LOTS
                    if ( result.getInt("Die Bank Qty") >  0)
                    {
                        log("In Die Bank " + lotNumber );

                        inventoryLot = (InventoryLot) m_dieBankDataMap.get( partNumber + fabLotNumber );
                        if ( inventoryLot == null )
                        {
                            inventoryLot = new InventoryLot(VENDOR_NAME_UNISEM, LOCATION_TYPE_DIE_BANK );
                            m_dieBankDataMap.put( partNumber + fabLotNumber, inventoryLot );
                        }
                        int quantity = 0;
                        int wquantity = 0;
                        if (inventoryLot.getQtyIn() != null)
                        {
                            try
                            {
                                quantity = Integer.parseInt(inventoryLot.getQtyIn());
                                wquantity = Integer.parseInt(inventoryLot.getWaferQtyIn());
                            }
                            catch (NumberFormatException ignore) {
                            }

                            if ( result.getInt("Die Bank Qty") == result.getInt("Wafer Qty") && result.getInt("Die Bank Qty") < 25 )
                            {
                                int fabProcessStepId = NewAdaptorDAO.getProcessStepId( partNumber, WIP_TYPE_FAB, WIP_TYPE_FAB );
                                int gdpw = 0;
                                try
                                {
                                    gdpw = Integer.parseInt(NewProductDAO.getProcessParameterValue( null, fabProcessStepId, ParameterTypes.grossDieWafer ) ) ;
                                }
                                catch( NumberFormatException nfe ) { gdpw = 0; }

                                quantity += result.getInt("Wafer Qty") * gdpw;
                                wquantity += result.getInt("Wafer Qty");
                            }
                            else
                            {
                                quantity += result.getInt("Die Bank Qty");
                                wquantity += result.getInt("Wafer Qty");
                            }

                        }
                        else
                        {
                            quantity = result.getInt("Die Bank Qty");
                            wquantity = result.getInt("Wafer Qty");

                            if ( quantity == wquantity && quantity < 25 )
                            {
                                int fabProcessStepId = NewAdaptorDAO.getProcessStepId( partNumber, WIP_TYPE_FAB, WIP_TYPE_FAB );
                                int gdpw = 0;
                                try
                                {
                                    gdpw = Integer.parseInt(NewProductDAO.getProcessParameterValue( null, fabProcessStepId, ParameterTypes.grossDieWafer ) ) ;
                                }
                                catch( NumberFormatException nfe ) { gdpw = 0; }

                                quantity = wquantity * gdpw;
                            }
                        }

                        if ( quantity > 0 )
                        {
                            inventoryLot.setLotNumber( fabLotNumber );
                            inventoryLot.setPartNumber( partNumber );
                            inventoryLot.setStatus( LOT_STATUS_RUNNING );
                            inventoryLot.setFabLotNumber( fabLotNumber );
                            inventoryLot.setCategory( LOT_CATEGORY_TYPE_PROD );
                            inventoryLot.setQtyIn( quantity +"" );
                            inventoryLot.setWaferQtyIn( wquantity +"" );
                            if ( result.getString("Fact Recv Date") != null )
                            {
                                inventoryLot.setDateIn( StringUtils.formatDate(result.getString("Fact Recv Date"), "dd/MM/yyyy", "MM/dd/yyyy") );
                            }
                        }
                    }

                    //ASSEMBLY
                    if( result.getInt("Saw") > 0 || result.getInt("DA") > 0 || result.getInt("WB") > 0 || result.getInt("Mold") > 0
                        || result.getInt("DFlash") > 0 || result.getInt("Marking") > 0 || result.getInt("PMC") > 0 || result.getInt("Djunk") > 0
                        || result.getInt("SPlate") > 0 || result.getInt("Form") > 0 || result.getInt("FVI") > 0 || result.getInt("Pack") > 0
                        || result.getInt("FG Store") > 0 )
                    {
                        log( "In Assembly " + lotNumber ) ;

                        assemblyLot = (AssemblyLot) m_assyWipDataMap.get( partNumber + lotNumber + fabLotNumber );
                        if (assemblyLot == null)
                        {
                            assemblyLot = new AssemblyLot( VENDOR_NAME_UNISEM );
                            m_assyWipDataMap.put( partNumber + lotNumber + fabLotNumber, assemblyLot);
                        }

                        // FOR SETTING THE QTY IN
                        if( result.getInt("Saw") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("Saw") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("Saw")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("Saw") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"Saw".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", Saw") ;
                            }
                            else
                            {
                                assemblyLot.setStage("Saw");
                            }
                        }
                        if( result.getInt("DA") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("DA") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("DA")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("DA") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"Die Attach".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", Die Attach") ;
                            }
                            else
                            {
                                assemblyLot.setStage("Die Attach");
                            }
                        }
                        if( result.getInt("WB") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("WB") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("WB")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("WB") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"Wire Bond".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", Wire Bond") ;
                            }
                            else
                            {
                                assemblyLot.setStage("Wire Bond");
                            }
                        }
                        if( result.getInt("Mold") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("Mold") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("Mold")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("Mold") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"Molding".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", Molding") ;
                            }
                            else
                            {
                                assemblyLot.setStage("Molding");
                            }
                        }
                        if( result.getInt("DFlash") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("DFlash") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("DFlash")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("DFlash") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"DFlash".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", DFlash") ;
                            }
                            else
                            {
                                assemblyLot.setStage("DFlash");
                            }
                        }
                        if( result.getInt("Marking") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("Marking") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("Marking")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("Marking") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"Marking".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", Marking") ;
                            }
                            else
                            {
                                assemblyLot.setStage("Marking");
                            }
                        }
                        if( result.getInt("PMC") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("PMC") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("PMC")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("PMC") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"PMC".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", PMC") ;
                            }
                            else
                            {
                                assemblyLot.setStage("PMC");
                            }
                        }
                        if( result.getInt("Djunk") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("Djunk") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("Djunk")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("Djunk") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"Djunk".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", Djunk") ;
                            }
                            else
                            {
                                assemblyLot.setStage("Djunk");
                            }
                        }
                        if( result.getInt("SPlate") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("SPlate") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("SPlate")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("SPlate") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"SPlate".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", SPlate") ;
                            }
                            else
                            {
                                assemblyLot.setStage("SPlate");
                            }
                        }

                        if( result.getInt("Form") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("Form") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("Form")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("Form") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"Forming".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", Forming") ;
                            }
                            else
                            {
                                assemblyLot.setStage("Forming");
                            }
                        }
                        if( result.getInt("FVI") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("FVI") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("FVI")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("FVI") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"FVI".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", FVI") ;
                            }
                            else
                            {
                                assemblyLot.setStage("FVI");
                            }
                        }
                        if( result.getInt("Pack") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("Pack") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("Pack")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("Pack") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"Pack".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", Pack") ;
                            }
                            else
                            {
                                assemblyLot.setStage("Pack");
                            }
                        }
                        if( result.getInt("FG Store") > 0 )
                        {
                            assemblyLot = (AssemblyLot) m_assyWipDataMap.get(partNumber + lotNumber + fabLotNumber);

                            if( assemblyLot.getQtyIn() != null )
                            {
                                try
                                {
                                    assemblyLot.setQtyIn( ( Integer.parseInt( assemblyLot.getQtyIn() ) + result.getInt("FG Store") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    assemblyLot.setQtyIn( result.getInt("FG Store")+ "");
                                }
                            }
                            else
                            {
                                assemblyLot.setQtyIn( result.getInt("FG Store") +"" );
                            }
                            if ( assemblyLot.getStage() != null && !"FG Store".equalsIgnoreCase( assemblyLot.getStage() ) )
                            {
                                assemblyLot.setStage ( assemblyLot.getStage() +", FG Store") ;
                            }
                            else
                            {
                                assemblyLot.setStage("FG Store");
                            }
                        }

                        if ( assemblyLot.getQtyIn() != null && assemblyLot.getQtyIn().equalsIgnoreCase("0") == false )
                        {
                            assemblyLot.setLotNumber( lotNumber );
                            assemblyLot.setDeviceName( partNumber );
                            assemblyLot.setStatus( LOT_STATUS_RUNNING );
                            assemblyLot.setFabLotNumber( fabLotNumber );
                            assemblyLot.setPackageType( result.getString("Package Name Ext") );
                            assemblyLot.setPONumber( result.getString("Cust Po Num") );
                            assemblyLot.setCategory( LOT_CATEGORY_TYPE_PROD );
                            if ( result.getString("Load Date") != null )
                            {
                                assemblyLot.setDateIn( StringUtils.formatDate(result.getString("Load Date"), "dd/MM/yyyy", "MM/dd/yyyy") );
                            }

                            if ( result.getString("Fo Cast Ship Date") != null )
                            {
                                assemblyLot.setExpectedDateOut( StringUtils.formatDate(result.getString("Fo Cast Ship Date"),"dd/MM/yyyy", "MM/dd/yyyy") );
                            }
                            assemblyLot.setProcessType( WIP_TYPE_ASSEMBLY );
                        }
                    }
                }
            }
        }
        catch( Exception e)
        {
            System.out.println("ERROR!! ERROR!! While parsing the UNISEM Assy Wip Data Details........" + e );
            e.printStackTrace();
            throw e;
        }

    }

    private void parseTestWipReport (String fileName ) throws Exception
    {
        if ( fileName == null ) throw new ScalarException( "Filename argument is null" );

        ParserResult result            = null;

        InventoryLot inventoryLot  = null;
        TestLot      testLot       = null;
        String partNumber       = null;
        String lotNumber        = null;
        String fabLotNumber     = null;
        try
        {
            File detailWipFile = new File( fileName );
            if ( !detailWipFile.exists() )
            {
                throw new ScalarException( fileName + " doesnt exist" );
            }

            Parser parser = ParserFactory.getJXLXLSParser( detailWipFile );
            log( "\nFound " + fileName );
            log( "\nParsing the file for TEST Wip Report..." );
            System.out.println( "\nFound " + fileName );
            System.out.println( "\nParsing the file for TEST WIP Report..." );

            ((JXLXLSParserImpl)parser).setHeaderRowIdx(5);
            ((JXLXLSParserImpl)parser).setDataStartRowIdx(6);

            result = parser.parse();

            while ( result.next() )
            {
                 partNumber = result.getString("Device");
                 lotNumber  = result.getString("LotNum");
                 fabLotNumber = result.getString("SublotNum");
                 if (fabLotNumber == null )
                 {
                     fabLotNumber = lotNumber;
                 }
                if ( lotNumber != null && lotNumber.trim().length() > 0 && partNumber != null && partNumber.trim().length() > 0)
                {
                    if ( lotNumber.indexOf("$") != -1 )
                    {
                        lotNumber = lotNumber.substring(0, lotNumber.indexOf("$") );
                    }
                    if ( partNumber.indexOf(".") != -1 )
                    {
                        partNumber = partNumber.substring(0, partNumber.lastIndexOf(".") );
                    }
                    if( result.getInt("Test Bank Qty") > 0 || result.getInt("Test1") > 0 || result.getInt("Low Yield Test1") > 0
                        || result.getInt("Test2") > 0 || result.getInt("Low Yield Test2") > 0 || result.getInt("QATest1") > 0
                        || result.getInt("Resc Test") > 0 || result.getInt("QATest2") > 0 || result.getInt("QAVis") > 0 || result.getInt("Lead Scan") > 0
                        || result.getInt("Test Bank15") > 0 )
                    {
                        log( "In Test " + lotNumber ) ;

                        testLot = (TestLot)m_testDataMap.get( partNumber + lotNumber+ fabLotNumber );

                        if ( testLot == null )
                        {
                            testLot = new TestLot( VENDOR_NAME_UNISEM, LOCATION_TYPE_FT );
                            m_testDataMap.put( partNumber + lotNumber + fabLotNumber , testLot );
                        }
                        if (result.getInt("Test Bank Qty") > 0 )
                        {
                            testLot = (TestLot)m_testDataMap.get( partNumber + lotNumber+ fabLotNumber );

                            if( testLot.getQtyIn() != null )
                            {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + result.getInt("Test Bank Qty") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getInt("Test Bank Qty")+ "");
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getInt("Test Bank Qty") +"" );
                            }
                            if ( testLot.getStage() != null && !"Test Bank".equalsIgnoreCase( testLot.getStage() ) )
                            {
                                testLot.setStage ( testLot.getStage() +", Test Bank") ;
                            }
                            else
                            {
                                testLot.setStage("Test Bank");
                            }
                        }
                        if (result.getInt("Test1") > 0 )
                        {
                            testLot = (TestLot)m_testDataMap.get( partNumber + lotNumber+ fabLotNumber );

                            if( testLot.getQtyIn() != null )
                            {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + result.getInt("Test1") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getInt("Test1")+ "");
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getInt("Test1") +"" );
                            }
                            if ( testLot.getStage() != null && !"Test1".equalsIgnoreCase( testLot.getStage() ) )
                            {
                                testLot.setStage ( testLot.getStage() +", Test1") ;
                            }
                            else
                            {
                                testLot.setStage("Test1");
                            }
                        }
                        // Low Yield Test1
                        if (result.getInt("Low Yield Test1") > 0 )
                        {
                            testLot = (TestLot)m_testDataMap.get( partNumber + lotNumber+ fabLotNumber );

                            if( testLot.getQtyIn() != null )
                            {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + result.getInt("Low Yield Test1") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getInt("Low Yield Test1")+ "");
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getInt("Low Yield Test1") +"" );
                            }
                            if ( testLot.getStage() != null && !"Low Yield Test1".equalsIgnoreCase( testLot.getStage() ) )
                            {
                                testLot.setStage ( testLot.getStage() +", Low Yield Test1") ;
                            }
                            else
                            {
                                testLot.setStage("Low Yield Test1");
                            }
                        }
                        if (result.getInt("Test2") > 0 )
                        {
                            testLot = (TestLot)m_testDataMap.get( partNumber + lotNumber+ fabLotNumber );

                            if( testLot.getQtyIn() != null )
                            {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + result.getInt("Test2") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getInt("Test2")+ "");
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getInt("Test2") +"" );
                            }
                            if ( testLot.getStage() != null && !"Test2".equalsIgnoreCase( testLot.getStage() ) )
                            {
                                testLot.setStage ( testLot.getStage() +", Test2") ;
                            }
                            else
                            {
                                testLot.setStage("Test2");
                            }
                        }
                        if (result.getInt("Low Yield Test2") > 0 )
                        {
                            testLot = (TestLot)m_testDataMap.get( partNumber + lotNumber+ fabLotNumber );

                            if( testLot.getQtyIn() != null )
                            {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + result.getInt("Low Yield Test2") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getInt("Low Yield Test2")+ "");
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getInt("Low Yield Test2") +"" );
                            }
                            if ( testLot.getStage() != null && !"Low Yield Test2".equalsIgnoreCase( testLot.getStage() ) )
                            {
                                testLot.setStage ( testLot.getStage() +", Low Yield Test2") ;
                            }
                            else
                            {
                                testLot.setStage("Low Yield Test2");
                            }
                        }
                        if (result.getInt("QATest1") > 0 )
                        {
                            testLot = (TestLot)m_testDataMap.get( partNumber + lotNumber+ fabLotNumber );

                            if( testLot.getQtyIn() != null )
                            {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + result.getInt("QATest1") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getInt("QATest1")+ "");
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getInt("QATest1") +"" );
                            }
                            if ( testLot.getStage() != null && !"QATest1".equalsIgnoreCase( testLot.getStage() ) )
                            {
                                testLot.setStage ( testLot.getStage() +", QATest1") ;
                            }
                            else
                            {
                                testLot.setStage("QATest1");
                            }
                        }
                        if (result.getInt("Resc Test") > 0 )
                        {
                            testLot = (TestLot)m_testDataMap.get( partNumber + lotNumber+ fabLotNumber );

                            if( testLot.getQtyIn() != null )
                            {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + result.getInt("Resc Test") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getInt("Resc Test")+ "");
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getInt("Resc Test") +"" );
                            }
                            if ( testLot.getStage() != null && !"Resc Test".equalsIgnoreCase( testLot.getStage() ) )
                            {
                                testLot.setStage ( testLot.getStage() +", Resc Test") ;
                            }
                            else
                            {
                                testLot.setStage("Resc Test");
                            }
                        }
                        if (result.getInt("QATest2") > 0 )
                        {
                            testLot = (TestLot)m_testDataMap.get( partNumber + lotNumber+ fabLotNumber );

                            if( testLot.getQtyIn() != null )
                            {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + result.getInt("QATest2") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getInt("QATest2")+ "");
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getInt("QATest2") +"" );
                            }
                            if ( testLot.getStage() != null && !"QATest2".equalsIgnoreCase( testLot.getStage() ) )
                            {
                                testLot.setStage ( testLot.getStage() +", QATest2") ;
                            }
                            else
                            {
                                testLot.setStage("QATest2");
                            }
                        }
                        if (result.getInt("QAVis") > 0 )
                        {
                            testLot = (TestLot)m_testDataMap.get( partNumber + lotNumber+ fabLotNumber );

                            if( testLot.getQtyIn() != null )
                            {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + result.getInt("QAVis") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getInt("QAVis")+ "");
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getInt("QAVis") +"" );
                            }
                            if ( testLot.getStage() != null && !"QAVis".equalsIgnoreCase( testLot.getStage() ) )
                            {
                                testLot.setStage ( testLot.getStage() +", QAVis") ;
                            }
                            else
                            {
                                testLot.setStage("QAVis");
                            }
                        }
                        //END QAVis
                        if (result.getInt("Lead Scan") > 0 )
                        {
                            testLot = (TestLot)m_testDataMap.get( partNumber + lotNumber+ fabLotNumber );

                            if( testLot.getQtyIn() != null )
                            {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + result.getInt("Lead Scan") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getInt("Lead Scan")+ "");
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getInt("Lead Scan") +"" );
                            }
                            if ( testLot.getStage() != null && !"Lead Scan".equalsIgnoreCase( testLot.getStage() ) )
                            {
                                testLot.setStage ( testLot.getStage() +", Lead Scan") ;
                            }
                            else
                            {
                                testLot.setStage("Lead Scan");
                            }
                        }
                        if (result.getInt("Test Bank15") > 0 )
                        {
                            testLot = (TestLot)m_testDataMap.get( partNumber + lotNumber+ fabLotNumber );

                            if( testLot.getQtyIn() != null )
                            {
                                try
                                {
                                    testLot.setQtyIn( ( Integer.parseInt( testLot.getQtyIn() ) + result.getInt("Test Bank15") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    testLot.setQtyIn( result.getInt("Test Bank15")+ "");
                                }
                            }
                            else
                            {
                                testLot.setQtyIn( result.getInt("Test Bank15") +"" );
                            }
                            if ( testLot.getStage() != null && !"Test Bank15".equalsIgnoreCase( testLot.getStage() ) )
                            {
                                testLot.setStage ( testLot.getStage() +", Test Bank15") ;
                            }
                            else
                            {
                                testLot.setStage("Test Bank15");
                            }
                        }

                        if ( testLot.getQtyIn() != null && !"0".equalsIgnoreCase( testLot.getQtyIn() ) )
                        {
                            testLot.setPartNumber( partNumber );
                            testLot.setLotNumber( lotNumber );
                            if (result.getDate("Load Date") != null )
                            {
                               testLot.setDateIn( StringUtils.formatDateToString(result.getDate("Load Date") )); 
                            }
                            else if (result.getDate("Fact Recv Date") != null )
                            {
                                testLot.setDateIn( StringUtils.formatDateToString(result.getDate("Fact Recv Date") ));
                            }
                            testLot.setFabLotNumber( fabLotNumber );
                            testLot.setStatus( LOT_STATUS_RUNNING );
                            testLot.setPoNumber( result.getString("Cust Po Num"));
                            if (result.getDate("Fo Cast Ship Date") != null )
                            {
                                testLot.setExpecetedDate( StringUtils.formatDateToString(result.getDate("Fo Cast Ship Date") )  );
                            }
                            testLot.setCategory( LOT_CATEGORY_TYPE_PROD );
                        }
                    } //End of Test

                    //T&R WIP
                     if ( result.getInt("Tube Pack") > 0  || result.getInt("Tape Reel") > 0 )
                     {
                         inventoryLot = m_trDataMap.get( partNumber + lotNumber + fabLotNumber );

                        if( inventoryLot == null )
                        {
                            inventoryLot = new InventoryLot( VENDOR_NAME_UNISEM,  LOCATION_TYPE_TAPE_REEL);
                            m_trDataMap.put(  partNumber + lotNumber + fabLotNumber , inventoryLot );
                        }
                        if (result.getInt("Tube Pack") > 0 )
                        {
                            inventoryLot = m_trDataMap.get( partNumber + lotNumber + fabLotNumber );

                            if( inventoryLot.getQtyIn() != null )
                            {
                                try
                                {
                                    inventoryLot.setQtyIn( ( Integer.parseInt( inventoryLot.getQtyIn() ) + result.getInt("Tube Pack") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    inventoryLot.setQtyIn( result.getInt("Tube Pack")+ "");
                                }
                            }
                            else
                            {
                                inventoryLot.setQtyIn( result.getInt("Tube Pack") +"" );
                            }
                            if ( inventoryLot.getStage() != null && !"Tube Pack".equalsIgnoreCase( inventoryLot.getStage() ) )
                            {
                                inventoryLot.setStage ( inventoryLot.getStage() +", Tube Pack") ;
                            }
                            else
                            {
                                inventoryLot.setStage("Tube Pack");
                            }
                        }
                        if ( result.getInt("Tape Reel") > 0 )
                        {
                            inventoryLot = m_trDataMap.get( partNumber + lotNumber + fabLotNumber );

                            if( inventoryLot.getQtyIn() != null )
                            {
                                try
                                {
                                    inventoryLot.setQtyIn( ( Integer.parseInt( inventoryLot.getQtyIn() ) + result.getInt("Tape Reel") ) + "" );
                                }
                                catch(Exception e)
                                {
                                    inventoryLot.setQtyIn( result.getInt("Tape Reel")+ "");
                                }
                            }
                            else
                            {
                                inventoryLot.setQtyIn( result.getInt("Tape Reel") +"" );
                            }
                            if ( inventoryLot.getStage() != null && !"Tape Reel".equalsIgnoreCase( inventoryLot.getStage() ) )
                            {
                                inventoryLot.setStage ( inventoryLot.getStage() +", Tape Reel") ;
                            }
                            else
                            {
                                inventoryLot.setStage("Tape Reel");
                            }
                        }
                        if( inventoryLot.getQtyIn() != null &&  !"0".equalsIgnoreCase(inventoryLot.getQtyIn()) )
                        {
                            inventoryLot.setPartNumber( partNumber );
                            inventoryLot.setLotNumber( lotNumber );
                            inventoryLot.setFabLotNumber( fabLotNumber );
                            inventoryLot.setDateIn(StringUtils.formatDateToString(new Date()));
                            inventoryLot.setStatus(LOT_STATUS_RUNNING);
                            inventoryLot.setLotCategory( LOT_CATEGORY_TYPE_PROD );
                            inventoryLot.setPkgType( result.getString("Pkg Lc") );
                            inventoryLot.setCustomerPO(result.getString("Cust Po Num"));
                        }
                     }
                     //FG
                     if (result.getInt("FGBank2") > 0 )
                     {
                        log("IN FG lotNumber = " + fabLotNumber);
                        inventoryLot = m_fgDataMap.get( partNumber + lotNumber + fabLotNumber );

                        if( inventoryLot == null )
                        {
                            inventoryLot = new InventoryLot( VENDOR_NAME_UNISEM,  LOCATION_TYPE_FG);
                            m_fgDataMap.put(  partNumber + lotNumber + fabLotNumber , inventoryLot );
                        }

                        if( inventoryLot.getQtyIn() != null )
                        {
                            try
                            {
                                inventoryLot.setQtyIn( ( Integer.parseInt( inventoryLot.getQtyIn() ) + result.getInt("FGBank2") ) + "" );
                            }
                            catch(Exception e)
                            {
                                inventoryLot.setQtyIn( result.getInt("FGBank2")+ "");
                            }
                        }
                        else
                        {
                            inventoryLot.setQtyIn( result.getInt("FGBank2") +"" );
                        }

                        if( inventoryLot.getQtyIn() != null &&  !"0".equalsIgnoreCase(inventoryLot.getQtyIn()) )
                        {
                            inventoryLot.setPartNumber( partNumber );
                            inventoryLot.setLotNumber( lotNumber );
                            inventoryLot.setFabLotNumber( fabLotNumber );
                            //inventoryLot.setQtyIn( quantity+"" );
                            inventoryLot.setDateIn(StringUtils.formatDateToString(new Date()));
                            inventoryLot.setStage("FGBank");
                            inventoryLot.setStatus(LOT_STATUS_RUNNING);
                            inventoryLot.setLotCategory( LOT_CATEGORY_TYPE_PROD );
                            inventoryLot.setPkgType( result.getString("Pkg Lc") );
                            inventoryLot.setCustomerPO(result.getString("Cust Po Num"));
                        }
                    } //END OF FG
                }
            }//End Of While
        }
        catch(Exception e )
        {
            System.out.println("ERROR!! ERROR!! While parsing the UNISEM TEST Wip Data Details........" + e );
            e.printStackTrace();
            throw e;
        }
    }
    
   /**
    *
    * @param message
    */
   private static void log( String message )
   {

       if ( message == null ) return;

       if ( m_parserLogger != null )
       {
           synchronized ( m_parserLogger )
           {
               m_parserLogger.logDebug ( message + LINE_SEPARATOR );
           }
       }
       else
       {
           System.out.println ( message );
       }
   }
}
